<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class DingdanController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    
    public function getIndex(Request $request)
    {   
        
        $data=$request->only('num','keywords');

        if(empty($data['num']))
        {
            $data['num']=10;
        }
        
        if(!$request->input('keywords')){
          
        $res=DB::table('sdingdan')->join('shangpin','sdingdan.sid','=','shangpin.id')->select('sdingdan.danhao','shangpin.name','shangpin.photo','sdingdan.status')->paginate($data['num']);
               
        }else{
            $keywords=$request->input('keywords');
            $res=DB::table('sdingdan')->join('shangpin','sdingdan.sid','=','shangpin.id')->select('sdingdan.danhao','shangpin.name','shangpin.photo','sdingdan.status')->where('sdiangdan.danhao','like','%'.$keywords.'%')->paginate($data['num']);
        }

        return view('Admin.dingdan.dingdan',['res'=>$res,'data'=>$data]);
        }
    

    
    }
